# 自己项目一的面包屑导航

# def get_breadcrumb(category):
#     """获取面包屑导航
#     :return 面包屑导航对应的
#     """
#     cat2 = category.parent  # 三级查二级,多查一:对方模型类.外键属性名
#     cat1 = cat2.parent  # 二级查一级
#     bread_crumb = {
#         "cat1": cat1,
#         "cat2": cat2,
#         "cat3": category,
#     }
#     return bread_crumb



#　项目二时,为了异步生成静态化页面,齐哥的面包屑导航
def get_breadcrumb(category):

    bread_crumb = {
        'cat1':'',
        'cat2':'',
        'cat3':'',
    }

    if category.parent is None:
        #没有父级,说明是一级分类
        bread_crumb['cat1']=category
    elif category.subs.count() == 0:
        #没有子级,说明是三级分类
        bread_crumb['cat3']=category
        #二级
        bread_crumb['cat2']=category.parent
        #一级
        bread_crumb['cat1']=category.parent.parent

    else:
        #二级分类
        bread_crumb['cat2']=category
        bread_crumb['cat1']=category.parent

    return bread_crumb